Exemplo n.º 1
0
 /**
  * @param xPDOObject|Article $object
  * @return array
  */
 public function prepareRow(xPDOObject $object)
 {
     $resourceArray = parent::prepareRow($object);
     if (!empty($resourceArray['publishedon'])) {
         $publishedon = strtotime($resourceArray['publishedon']);
         $resourceArray['publishedon_date'] = strftime($this->modx->getOption('articles.mgr_date_format', null, '%b %d'), $publishedon);
         $resourceArray['publishedon_time'] = strftime($this->modx->getOption('articles.mgr_time_format', null, '%H:%I %p'), $publishedon);
         $resourceArray['publishedon'] = strftime('%b %d, %Y %H:%I %p', $publishedon);
     }
     $resourceArray['action_edit'] = '?a=' . $this->editAction->get('id') . '&action=post/update&id=' . $resourceArray['id'];
     if (!array_key_exists('comments', $resourceArray)) {
         $resourceArray['comments'] = 0;
     }
     $this->modx->getContext($resourceArray['context_key']);
     $resourceArray['preview_url'] = $this->modx->makeUrl($resourceArray['id'], $resourceArray['context_key']);
     $trimLength = $this->modx->getOption('articles.mgr_article_content_preview_length', null, 300);
     $resourceArray['content'] = strip_tags($this->ellipsis($object->getContent(), $trimLength));
     $resourceArray['actions'] = array();
     $resourceArray['actions'][] = array('className' => 'edit', 'text' => $this->modx->lexicon('edit'));
     $resourceArray['actions'][] = array('className' => 'view', 'text' => $this->modx->lexicon('view'));
     if (!empty($resourceArray['deleted'])) {
         $resourceArray['actions'][] = array('className' => 'undelete', 'text' => $this->modx->lexicon('undelete'));
     } else {
         $resourceArray['actions'][] = array('className' => 'delete', 'text' => $this->modx->lexicon('delete'));
     }
     if (!empty($resourceArray['published'])) {
         $resourceArray['actions'][] = array('className' => 'unpublish', 'text' => $this->modx->lexicon('unpublish'));
     } else {
         $resourceArray['actions'][] = array('className' => 'publish orange', 'text' => $this->modx->lexicon('publish'));
     }
     return $resourceArray;
 }
Exemplo n.º 2
0
 public function prepareArray(array $resourceArray)
 {
     if ($this->getProperty('combo')) {
         $resourceArray['parents'] = array();
         $parents = $this->modx->getParentIds($resourceArray['id'], 2, array('context' => $resourceArray['context_key']));
         if (empty($parents[count($parents) - 1])) {
             unset($parents[count($parents) - 1]);
         }
         if (!empty($parents) && is_array($parents)) {
             $q = $this->modx->newQuery('msCategory', array('id:IN' => $parents));
             $q->select('id,pagetitle');
             if ($q->prepare() && $q->stmt->execute()) {
                 while ($row = $q->stmt->fetch(PDO::FETCH_ASSOC)) {
                     $key = array_search($row['id'], $parents);
                     if ($key !== false) {
                         $parents[$key] = $row;
                     }
                 }
             }
             $resourceArray['parents'] = array_reverse($parents);
         }
     } else {
         if ($resourceArray['parent'] != $this->parent) {
             $resourceArray['cls'] = 'multicategory';
             $resourceArray['category_name'] = $resourceArray['category_pagetitle'];
         } else {
             $resourceArray['cls'] = $resourceArray['category_name'] = '';
         }
         $resourceArray['price'] = round($resourceArray['price'], 2);
         $resourceArray['old_price'] = round($resourceArray['old_price'], 2);
         $resourceArray['weight'] = round($resourceArray['weight'], 3);
         $resourceArray['action_edit'] = '?a=' . $this->editAction->get('id') . '&action=post/update&id=' . $resourceArray['id'];
         $this->modx->getContext($resourceArray['context_key']);
         $resourceArray['preview_url'] = $this->modx->makeUrl($resourceArray['id'], $resourceArray['context_key']);
         $resourceArray['actions'] = array();
         $resourceArray['actions'][] = array('className' => 'edit', 'text' => $this->modx->lexicon('ms2_product_edit'));
         $resourceArray['actions'][] = array('className' => 'view', 'text' => $this->modx->lexicon('ms2_product_view'));
         if (!empty($resourceArray['deleted'])) {
             $resourceArray['actions'][] = array('className' => 'undelete green', 'text' => $this->modx->lexicon('ms2_product_undelete'));
         } else {
             $resourceArray['actions'][] = array('className' => 'delete', 'text' => $this->modx->lexicon('ms2_product_delete'));
         }
         if (!empty($resourceArray['published'])) {
             $resourceArray['actions'][] = array('className' => 'unpublish', 'text' => $this->modx->lexicon('ms2_product_unpublish'));
         } else {
             $resourceArray['actions'][] = array('className' => 'publish orange', 'text' => $this->modx->lexicon('ms2_product_publish'));
         }
     }
     return $resourceArray;
 }
Exemplo n.º 3
0
 /**
  * Calculate the TV rules
  * @return void
  */
 public function setTVRules()
 {
     $tvs = $this->getProperty('tvs', null);
     if ($tvs == null) {
         return;
     }
     $tvs = is_array($tvs) ? $tvs : $this->modx->fromJSON($tvs);
     foreach ($tvs as $tvData) {
         /** @var modTemplateVar $tv */
         $tv = $this->modx->getObject('modTemplateVar', $tvData['id']);
         if (empty($tv)) {
             continue;
         }
         if (empty($tvData['visible'])) {
             /** @var modActionDom $rule */
             $rule = $this->modx->newObject('modActionDom');
             $rule->set('set', $this->object->get('id'));
             $rule->set('action', $this->object->get('action'));
             $rule->set('name', 'tv' . $tv->get('id'));
             $rule->set('container', 'modx-panel-resource');
             $rule->set('rule', 'tvVisible');
             $rule->set('value', 0);
             $rule->set('constraint_class', $this->object->get('constraint_class'));
             $rule->set('constraint_field', $this->object->get('constraint_field'));
             $rule->set('constraint', $this->object->get('constraint'));
             $rule->set('active', true);
             if ($this->action && $this->action->get('controller') == 'resource/create') {
                 $rule->set('for_parent', true);
             }
             $rule->set('rank', 12);
             $this->newRules[] = $rule;
         }
         if (!empty($tvData['label'])) {
             $rule = $this->modx->newObject('modActionDom');
             $rule->set('set', $this->object->get('id'));
             $rule->set('action', $this->object->get('action'));
             $rule->set('name', 'tv' . $tv->get('id'));
             $rule->set('container', 'modx-panel-resource');
             $rule->set('rule', 'tvTitle');
             $rule->set('value', $tvData['label']);
             $rule->set('constraint_class', $this->object->get('constraint_class'));
             $rule->set('constraint_field', $this->object->get('constraint_field'));
             $rule->set('constraint', $this->object->get('constraint'));
             $rule->set('active', true);
             if ($this->action && $this->action->get('controller') == 'resource/create') {
                 $rule->set('for_parent', true);
             }
             $rule->set('rank', 11);
             $this->newRules[] = $rule;
         }
         if ($tv->get('default_text') != $tvData['default_value']) {
             $rule = $this->modx->newObject('modActionDom');
             $rule->set('set', $this->object->get('id'));
             $rule->set('action', $this->object->get('action'));
             $rule->set('name', 'tv' . $tv->get('id'));
             $rule->set('container', 'modx-panel-resource');
             $rule->set('rule', 'tvDefault');
             $rule->set('value', $tvData['default_value']);
             $rule->set('constraint_class', $this->object->get('constraint_class'));
             $rule->set('constraint_field', $this->object->get('constraint_field'));
             $rule->set('constraint', $this->object->get('constraint'));
             $rule->set('active', true);
             if ($this->action && $this->action->get('controller') == 'resource/create') {
                 $rule->set('for_parent', true);
             }
             $rule->set('rank', 10);
             $this->newRules[] = $rule;
         }
         if (!empty($tvData['tab']) && $tvData['tab'] != 'modx-panel-resource-tv') {
             $rule = $this->modx->newObject('modActionDom');
             $rule->set('set', $this->object->get('id'));
             $rule->set('action', $this->object->get('action'));
             $rule->set('name', 'tv' . $tv->get('id'));
             $rule->set('container', 'modx-panel-resource');
             $rule->set('rule', 'tvMove');
             $rule->set('value', $tvData['tab']);
             $rule->set('constraint_class', $this->object->get('constraint_class'));
             $rule->set('constraint_field', $this->object->get('constraint_field'));
             $rule->set('constraint', $this->object->get('constraint'));
             $rule->set('active', true);
             if ($this->action && $this->action->get('controller') == 'resource/create') {
                 $rule->set('for_parent', true);
             }
             /* add 20 to rank to make sure happens after tab create */
             $rank = 20 + (int) $tvData['rank'];
             $rule->set('rank', $rank);
             $this->newRules[] = $rule;
         }
     }
 }