public function findByIds($ids, $query)
 {
     $result = array();
     if ($query->isEmpty()) {
         return $result;
     }
     $sql = $this->_getSearchSql($query);
     $sql .= " AND " . sqlIn('object_id', $ids);
     return $this->_getDbResult($sql);
 }
  static public function getIdsByNames($names)
  {
    $db = Limb :: toolkit()->getDB();

    $db->sqlSelect('sys_behaviour', 'id', sqlIn('name', $names));

    $result = array();
    while($row = $db->fetchRow())
      $result[] = $row['id'];

    return $result;
  }
 public function loadMetadata()
 {
     $ids_array = $this->_getPathObjectsIdsArray();
     if (!count($ids_array)) {
         return false;
     }
     $ids_array = array_reverse($ids_array);
     $metadata_db_table = Limb::toolkit()->createDBTable($this->metadata_db_table_name);
     $objects_metadata = $metadata_db_table->getList(sqlIn('object_id', $ids_array), '', 'object_id');
     if (!count($objects_metadata)) {
         return false;
     }
     $this->_processLoadedMetadata($ids_array, $objects_metadata);
     return true;
 }
 public function saveObjectsAccess($policy_array, $accessor_type, $accessor_ids = array())
 {
     $db_table = Limb::toolkit()->createDBTable('SysObjectAccess');
     foreach ($policy_array as $object_id => $access_data) {
         $conditions = 'object_id=' . (int) $object_id . ' AND accessor_type=' . $accessor_type;
         if (count($accessor_ids)) {
             $conditions .= ' AND ' . sqlIn('accessor_id', $accessor_ids);
         }
         $db_table->delete($conditions);
         foreach ($access_data as $accessor_id => $access) {
             if (!$access) {
                 continue;
             }
             $data = array();
             $data['access'] = 1;
             $data['accessor_id'] = $accessor_id;
             $data['object_id'] = $object_id;
             $data['accessor_type'] = $accessor_type;
             $db_table->insert($data);
         }
     }
     return true;
 }
Ejemplo n.º 5
0
  protected function _cascadeDelete($affected_rows)
  {
    if(self :: autoConstraintsEnabled())
      return;

    if (!count($affected_rows))
      return;

    foreach($this->_constraints as $id => $constraints_array)
    {
      foreach($constraints_array as $key => $constraint_params)
      {
        $table_name = $constraint_params['table_name'];
        $column_name = $constraint_params['field'];

        $class_name = $this->_mapTableNameToClass($table_name);

        $db_table = Limb :: toolkit()->createDBTable($class_name);

        if(!$db_table->hasColumn($column_name))
        {
          throw new SQLException('column not found while cascade deleting',
            null,
            array(
              'table' => $table_name,
              'column_name' => $column_name
            )
          );
        }

        $values = array();
        foreach($affected_rows as $data)
          $values[] = $data[$id];

        $db_table->delete(
          sqlIn($column_name, $values, $db_table->getColumnType($column_name)));
      }
    }
  }
  public function fetchBackLinks($target_node_id, $groups_ids = array())
  {
    $link_db_table = Limb :: toolkit()->createDBTable('SysNodeLink');

    $conditions = "target_node_id = {$target_node_id}";

    if (is_array($groups_ids) &&  count($groups_ids))
      $conditions .= ' AND ' . sqlIn('group_id', $groups_ids);

    return $link_db_table->getList($conditions, 'priority ASC');
  }
  protected function _collectRawSqlParams()
  {
    $params = $this->raw_sql_params;

    if ($object_ids = $this->getAccessibleObjectIds())
      $params['conditions'][] = ' AND ' . sqlIn('sso.id', $object_ids);

    if ($this->restriction_class_name)
    {
      $params['conditions'][] = ' AND sys_class.name = ' . $this->restriction_class_name;
    }

    if ($this->behaviours)
    {
      $params['conditions'][] = ' AND ' . sqlIn('sso.behaviour_id', $this->_getBehavioursIds());
    }

    return $params;
  }
  function testGetListByInCondition()
  {
    $data = array(
      0 => array('id' => null, 'title' =>  'wow', 'description' => 'description'),
      1 => array('id' => null, 'title' =>  'wow!', 'description' => 'description2')
    );

    $this->db_table_test->insert($data[0]);
    $this->db_table_test->insert($data[1]);

    $result = $this->db_table_test->getList(
      sqlIn('title', array('wow!', 'wow')));

    $this->assertNotEqual($result, array());

    $this->assertEqual(sizeof($result), 2);

    $arr = reset($result);
    $this->assertEqual($arr['description'], 'description');

    $arr = next($result);
    $this->assertEqual($arr['description'], 'description2');
  }