v7‰PNG  IHDR Ÿ f Õ†C1 sRGB ®Îé gAMA ± üa pHYs à ÃÇo¨d GIDATx^íÜL”÷ð÷Yçªö("Bh_ò«®¸¢§q5kÖ*:þ0A­ºšÖ¥]VkJ¢M»¶f¸±8\k2íll£1]q®ÙÔ‚ÆT Content.php000064400000015202152101622350006664 0ustar00joinSort($this->createAdapter()); parent::__construct('_'.$this->getContentGridId(), $this->getTitle(), $adapter, $request, $view); $this->setEventId('gridContent' . ucfirst($this->getContentGridId())); $this->addCallback(self::CB_AFTER_INSERT, array($this, 'afterInsert')); $this->addCallback(self::CB_AFTER_UPDATE, array($this, 'afterInsert')); $this->addCallback(self::CB_VALUES_TO_FORM, array($this, '_valuesToForm')); foreach ($this->getActions() as $action) $action->setTarget('_top'); } /** * Add join to resource_access_sort and sort field * to be present in the result */ protected function joinSort(Am_Query $q) { $q->getTable()->addDefaultSort($q); return $q; } public function getTitle() { return ___(ucfirst($this->getContentGridId())); } public function getContentGridId() { $id = preg_split('#[\\\\_]#', get_class($this)); $id = strtolower(array_pop($id)); return $id; } function renderAccessTitle(ResourceAbstract $r) { $title = $this->escape($r->title); if (!empty($r->hide)) $title = "$title"; return $this->renderTd($title, false); } protected function initGridFields() { $this->addField(new Am_Grid_Field_Expandable('_access', ___('Products'), false)) ->setPlaceholder(array($this, 'getPlaceholder')) ->setRenderFunction(array($this, 'renderProducts')) ->setGetFunction(array($this, 'getProducts')) ->setMaxLength(200); $this->addField('_link', ___('Link'), false)->setRenderFunction(array($this, 'renderLink')); $this->actionAdd(new Am_Grid_Action_SortContent()); parent::initGridFields(); } public function renderLink(ResourceAbstract $resource) { $html = ""; $url = $resource->getUrl(); if (!empty($url)) $html = sprintf('%s', $this->escape($url), ___('link')); return $this->renderTd($html, false); } public function renderProducts($obj, $fieldName, $controller, $field) { return $this->renderTd($field->get($obj, $controller), false); } public function renderCategory(ResourceAbstract $e) { $res = array(); $options = $this->getDi()->resourceCategoryTable->getOptions(); foreach ($e->getCategories() as $resc_id) { $res[] = $options[$resc_id]; } return $this->renderTd(implode(", ", $res)); } public function getProducts(ResourceAbstract $resource) { $s = ""; foreach ($resource->getAccessList() as $access) { $l = ""; if ($access->getStart()) $l .= " from " . $access->getStart(); if ($access->getStop()) $l .= " to " . $access->getStop(); $s .= sprintf("%s %s %s
\n", $access->getClassTitle(), $access->getTitle(), $l); } return $s; } public function getPlaceholder($val, ResourceAbstract $resource) { return ___('%d access records…', count($resource->getAccessList())); } public function afterInsert(array & $values, ResourceAbstract $record) { $record->setAccess($values['_access']); } public function _valuesToForm(array & $values, Am_Record $record) { $values['_access'] = $this->getRecord()->getAccessList(); } public function renderPath(ResourceAbstractFile $file) { $upload = $file->getUpload(); try{ $file->isLocal(); } catch (Exception $e) { if (!$upload) return $this->renderTd( '' . ___('The file has been removed from disk or corrupted. Please re-upload it.') . '' . ' (' . ___('Error from Storage Engine') . ': ' . $this->escape($e->getMessage()) . ')' . '
' . ___('Real Path') . ': ' . $this->escape($file->path), false); } return $upload && !file_exists($upload->getFullPath()) ? $this->renderTd( '
' . ___('The file has been removed from disk or corrupted. Please re-upload it.') . ''. '
' . $this->escape($upload->getName() . '/' . $upload->getFilename()) . '
' . '
', false) : $this->renderTd(sprintf('%s (%s)', $this->escape($file->getDisplayFilename()), $file->getStorageId()), false); } protected function getTemplateOptions() { $folders = array( AM_APPLICATION_PATH . '/default/views/' => 1, AM_APPLICATION_PATH . '/default/themes/' . $this->getDi()->config->get('theme') => 2, ); $ret = array( null => 'layout.phtml' ); foreach (array_keys($folders) as $f) { foreach ((array) glob($f . '/layout*.phtml') as $file) { if (!strlen($file)) continue; $file = basename($file); if ($file == 'layout.phtml') continue; $ret[$file] = $file; } } return $ret; } protected function addCategoryToForm($form) { $category = $form->addCategory('_category', null, array( 'base_url' => 'admin-resource-categories', 'link_title' => ___('Edit Categories'), 'title' => ___('Content Categories'), 'options' => Am_Di::getInstance()->resourceCategoryTable->getOptions())) ->setLabel(___("Content Categories\n" . "these categories will be shown in user's menu if user has access to " . "resources in this category. You can uses these categories to organize " . "your content by pages")); } }