Exemple #1
0
 /**
  * Get material entity by URL(s).
  *
  * @param QueryInterface $query Object for performing database queries
  * @param array|string $url Material URL or collection of material URLs
  * @param self|array|null $return Variable where request result would be returned
  * @return bool|self True if material entities has been found
  */
 public static function byUrl(QueryInterface $query, $url, &$return = array())
 {
     // Get entities by filtered identifiers
     $return = $query->entity(get_called_class())->where('Url', $url)->where('Active', 1)->first();
     // If only one argument is passed - return null, otherwise bool
     return func_num_args() > 2 ? $return !== null : $return;
 }
Exemple #2
0
 /**
  * Find material record by identifier
  * @param \samsonframework\orm\QueryInterface Query object
  * @param string $identifier Material identifier
  * @param mixed $return Found material is returned here
  * @return bool True if material was found by identifier
  */
 public static function byId(\samsonframework\orm\QueryInterface $query, $identifier, &$return = null)
 {
     // Get material safely
     if ($query->id($identifier)->first($return)) {
         return true;
     } else {
         // Material not found
         return false;
     }
 }
Exemple #3
0
 /** @inheritdoc */
 public function render(RenderInterface $renderer, QueryInterface $query, $object)
 {
     // Get all available groups from db
     $groupSelect = array();
     foreach ($query->className('group')->cond('Active', 1)->exec() as $group) {
         $groupSelect[] = $group->GroupID . ':' . $group->Name;
     }
     // Set view
     return $renderer->view($this->innerView)->set('class', $this->css)->set($object, 'item')->set(m('samsoncms_input_application')->createFieldByType($query, 4, $object, $this->name)->build(implode(',', $groupSelect)), 'field')->output();
 }
Exemple #4
0
 /** @inheritdoc */
 public function __construct(RenderInterface $renderer, QueryInterface $query, Record $entity, field $field)
 {
     // Check if material have this gallery additional field stored
     if (!$query->className('materialfield')->cond('MaterialID', $entity->id)->cond('FieldID', $field->id)->first($this->materialField)) {
         // Create materialfield object
         $this->materialField = new \samson\activerecord\materialfield(false);
         $this->materialField->FieldID = $field->id;
         $this->materialField->MaterialID = $entity->id;
         $this->materialField->Active = 1;
         $this->materialField->save();
     }
     // Form tab name
     $this->name = t(isset($field->Name[0]) ? $field->Name : $this->name, true);
     // Call parent constructor to define all class fields
     parent::__construct($renderer, $query, $entity);
 }
Exemple #5
0
 public function testCreate()
 {
     $materialField = $this->getMockBuilder('\\samsoncms\\api\\MaterialField')->disableOriginalConstructor()->getMock();
     $materialField[MaterialField::F_PRIMARY] = 1;
     $materialField[Field::F_PRIMARY] = 1;
     $materialField[Material::F_PRIMARY] = 1;
     $materialField[MaterialField::F_VALUE] = '1';
     $materialField[MaterialField::F_NUMERIC] = '1';
     $materialField[MaterialField::F_KEY] = '1';
     $materialField[MaterialField::F_DELETION] = true;
     $materialField2 = $this->getMockBuilder('\\samsoncms\\api\\MaterialField')->disableOriginalConstructor()->getMock();
     $materialField2[MaterialField::F_PRIMARY] = 2;
     $materialField2[Field::F_PRIMARY] = 2;
     $materialField2[Material::F_PRIMARY] = 2;
     $materialField2[MaterialField::F_VALUE] = '2';
     $materialField2[MaterialField::F_NUMERIC] = '2';
     $materialField2[MaterialField::F_KEY] = '2';
     $materialField2[MaterialField::F_DELETION] = true;
     $this->query->method('exec')->willReturn(array($materialField, $materialField2));
     //		$table = new FieldsTable($this->query, 1, 1);
 }
 /** @inheritdoc */
 public function __construct(RenderInterface $renderer, QueryInterface $query, Record $entity, Navigation $structure)
 {
     $this->name = $structure->Name;
     $this->id .= $structure->Url != '' ? '_' . $structure->Url : '_' . $structure->Name;
     $this->structure = $structure;
     $this->entity = $entity;
     $rows = $query->entity(Material::class)->where(Material::F_PARENT, $entity->id)->where(Material::F_DELETION, true)->fields(Material::F_PRIMARY);
     if (count($rows)) {
         $this->size = $query->entity(NavigationMaterial::class)->where(NavigationMaterial::F_MATERIALID, $rows)->where(NavigationMaterial::F_STRUCTUREID, $structure->id)->where(NavigationMaterial::F_ACTIVE, true)->count();
     }
     // Get data about current tab
     $fieldWithMaterialCount = $query->entity(NavigationField::class)->join('field')->where('field_Type', 6)->where(NavigationField::F_STRUCTURE, $this->structure->id)->count();
     $localizedFieldsCount = $query->entity(NavigationField::class)->join('field')->where('field_local', 1)->where(NavigationField::F_STRUCTURE, $this->structure->id)->count();
     // If in this tab exists only material type field or don't exists localized fields
     if ($fieldWithMaterialCount > 0 || $localizedFieldsCount == 0) {
         // Create default sub tab
         $this->subTabs[] = new MaterialTableLocalized($renderer, $query, $entity, $structure, '');
         // If in this tab exists not material type fields and this fields localized then include their
     } else {
         //if (($fieldWithMaterialCount == 0) && ($localizedFieldsCount > 0))
         // Iterate available locales if we have localized fields
         foreach (SamsonLocale::$locales as $locale) {
             // Create child tab
             $subTab = new MaterialTableLocalized($renderer, $query, $entity, $structure, $locale);
             $this->subTabs[] = $subTab;
         }
     }
     // Call parent constructor to define all class fields
     parent::__construct($renderer, $query, $entity);
 }
Exemple #7
0
 /** Tests init */
 public function setUp()
 {
     \samson\core\Error::$OUTPUT = false;
     // Create Request mock
     $this->query = $this->getMockBuilder('\\samsonframework\\orm\\Query')->disableOriginalConstructor()->getMock();
     $materialfield = $this->getMockBuilder(MaterialField::ENTITY)->disableOriginalConstructor()->getMock();
     $gallery = $this->getMockBuilder(CMS::MATERIAL_IMAGES_RELATION_ENTITY)->disableOriginalConstructor()->getMock();
     $this->query->method('entity')->willReturn($this->query);
     $this->query->method('first')->willReturn($materialfield);
     $this->query->method('exec')->willReturn(array($gallery));
     $this->query->method('where')->willReturn($this->query);
     $this->query->method('count')->willReturn(10);
 }
Exemple #8
0
 /**
  * Find additional field value database record by its material and field identifiers.
  * This is generic method that should be used in nested classes to find its
  * records by some its primary key value.
  *
  * @param QueryInterface $query Query object instance
  * @param string $materialID Material identifier
  * @param string $fieldID Additional field identifier
  * @param mixed $return Variable to return found database record
  * @param string $locale Locale identifier
  * @return bool|null|self  Field instance or null if 3rd parameter not passed
  */
 public static function byFieldIDAndMaterialID(QueryInterface $query, $materialID, $fieldID, &$return = null, $locale = null)
 {
     $return = $query->entity(get_called_class())->where(Material::F_PRIMARY, $materialID)->where(Field::F_PRIMARY, $fieldID)->where(self::F_LOCALE, $locale)->where(Material::F_DELETION, 1)->exec();
     // If only one argument is passed - return null, otherwise bool
     return func_num_args() > 3 ? sizeof($return) : $return;
 }
Exemple #9
0
 /** @deprecated Use QueryInterface implementation */
 public function id($value)
 {
     $this->query->primary($value);
     return $this;
 }
Exemple #10
0
 /**
  * Get entity from database by identifier
  * @param int $identifier Entity identifier
  * @param \samsonframework\orm\Record Found entity
  * @return boolean
  */
 protected function findEntityByID($identifier, &$entity, $entityName = null)
 {
     // If no specific entity name is passed use application default entity name
     $entityName = !isset($entityName) ? $this->entity : $entityName;
     return $this->query->className($entityName)->id($identifier)->first($entity);
 }
Exemple #11
0
 /**
  * Generic collection constructor
  * @param RenderInterface $renderer View render object
  * @param QueryInterface $query Query object
  */
 public function __construct(RenderInterface $renderer, QueryInterface $query, PagerInterface $pager)
 {
     // Call parent initialization
     parent::__construct($renderer, $query->className('material'), $pager);
 }
Exemple #12
0
 /**
  * Generic collection constructor
  *
  * @param RenderInterface $renderer View render object
  * @param QueryInterface  $query    Query object
  */
 public function __construct(RenderInterface $renderer, QueryInterface $query, PagerInterface $pager)
 {
     // Call parent initialization
     parent::__construct($renderer, $query->entity('\\samson\\activerecord\\material'), $pager);
 }
Exemple #13
0
 /**
  * Function to cut off related and table materials
  *
  * @param QueryInterface $query Base entity query for modification
  */
 public function parentIdInjection(&$query)
 {
     // Cut off related and table materials
     $query->cond('parent_id', null)->order_by('Modyfied', 'DESC');
 }
Exemple #14
0
 /**
 * Find additional field database record by Name or ID.
 * This is generic method that should be used in nested classes to find its
 * records by some its primary key value.
 *
 * @param QueryInterface $query Query object instance
 * @param string         $nameOrID Additional field name or identifier
 * @param self $return Variable to return found database record
 *
 *@return bool|null|self  Field instance or null if 3rd parameter not passed
 */
 public static function byNameOrID(QueryInterface $query, $nameOrID, self &$return = null)
 {
     // Create id or URL condition
     $idOrUrl = new Condition('OR');
     $idOrUrl->add('FieldID', $nameOrID)->add('Name', $nameOrID);
     // Perform query
     $return = $query->entity(get_called_class())->whereCondition($idOrUrl)->first();
     // If only one argument is passed - return null, otherwise bool
     return func_num_args() > 1 ? $return == null : $return;
 }