Ejemplo n.º 1
1
 protected function setUp()
 {
     $this->dataMapper = $this->getMock('FSi\\Component\\DataGrid\\DataMapper\\DataMapperInterface');
     $this->dataMapper->expects($this->any())->method('getData')->will($this->returnCallback(function ($field, $object) {
         switch ($field) {
             case 'name':
                 return $object->getName();
                 break;
         }
     }));
     $this->dataMapper->expects($this->any())->method('setData')->will($this->returnCallback(function ($field, $object, $value) {
         switch ($field) {
             case 'name':
                 return $object->setName($value);
                 break;
         }
     }));
     $this->indexingStrategy = $this->getMock('FSi\\Component\\DataGrid\\Data\\IndexingStrategyInterface');
     $this->indexingStrategy->expects($this->any())->method('getIndex')->will($this->returnCallback(function ($object, $dataMapper) {
         if (is_object($object)) {
             return $object->getName();
         }
         return null;
     }));
     $this->factory = $this->getMock('FSi\\Component\\DataGrid\\DataGridFactoryInterface');
     $this->factory->expects($this->any())->method('getExtensions')->will($this->returnValue(array(new FooExtension())));
     $this->factory->expects($this->any())->method('getColumnType')->with($this->equalTo('foo'))->will($this->returnValue(new FooType()));
     $this->factory->expects($this->any())->method('hasColumnType')->with($this->equalTo('foo'))->will($this->returnValue(true));
     $this->datagrid = new DataGrid('grid', $this->factory, $this->dataMapper, $this->indexingStrategy);
 }
Ejemplo n.º 2
0
 /**
  * @dataProvider globalMappedData
  */
 public function testGlobalMapping($path, $data, $expected)
 {
     $mapper = new DataMapper();
     foreach ($data as $globalData) {
         $mapper->mapAll($globalData);
     }
     $this->assertEquals($expected, $mapper->data($path));
 }
Ejemplo n.º 3
0
 function testShouldListPossibleParents()
 {
     $mapper = new DataMapper($this->db);
     $parent1_id = $mapper->save(array('name' => 'Parent 1'));
     $mapper = new DataMapper($this->db);
     $parent2_id = $mapper->save(array('name' => 'Parent 1a', 'paths' => array($parent1_id)));
     $form = new Form($mapper);
     $expected = array($parent1_id => 'Parent 1', $parent1_id . '/' . $parent2_id => 'Parent 1a');
     $this->assertEquals($expected, $form->getElement('paths')->getMultiOptions());
 }
Ejemplo n.º 4
0
 function testShouldUpdateAddress()
 {
     $address = array('first_name' => 'Joshua', 'last_name' => 'Ribakoff', 'email' => '*****@*****.**', 'address' => '123 Test St', 'address2' => 'Suite 5', 'city' => 'Port St Lucie', 'state' => 'FL', 'postal' => '00123', 'country' => 'USA', 'phone' => '0101010101', 'fax' => '0202020202');
     $addressMapper = new DataMapper($this->db);
     $id = $addressMapper->save($address);
     $updatedAddress = array('id' => $id, 'first_name' => 'Joshua-updated', 'last_name' => 'Ribakoff-updated', 'email' => '*****@*****.**', 'address' => '123 Test St-updated', 'address2' => 'Suite 5-updated', 'city' => 'Port St Lucie-updated', 'state' => 'FL-updated', 'postal' => '12345', 'country' => 'USA-updated', 'phone' => '111111111', 'fax' => '2222222222');
     $addressMapper = new DataMapper($this->db);
     $id = $addressMapper->save($updatedAddress);
     $loadedAddress = $addressMapper->load($id);
     $this->assertSame($updatedAddress, $loadedAddress, 'should save new address');
 }
Ejemplo n.º 5
0
 function testShouldSaveCartAndItems()
 {
     $cart = new \Metator\Cart\Cart();
     $cart->add(1, 9.99);
     $cart->add(2, 4.99);
     $cart->setQuantity(2, 2);
     $order = array('items' => $cart, 'created' => '0000-00-00 00:00:00');
     $orderMapper = new DataMapper($this->db);
     $id = $orderMapper->save($order, null);
     $reloaded_order = $orderMapper->load($id);
     $this->assertEquals(array(1, 2), $reloaded_order['items']->items(), 'should save items');
 }
Ejemplo n.º 6
0
 function delete($object = '')
 {
     if (empty($object)) {
         $this->deattach();
     }
     return parent::delete($object);
 }
Ejemplo n.º 7
0
 public function __construct()
 {
     Cowl::timer('cowl init');
     @session_start();
     // I know that the @-notation is frowned upon, but adding it to session_start saves us unnecessary warnings
     Cache::setDir(COWL_CACHE_DIR);
     Current::initialize(COWL_DIR);
     if (COWL_CLI) {
         $this->parseCLIPath();
     } else {
         $this->parseRequestPath();
     }
     Cowl::timer('cowl set defaults');
     // Get and set all directories for various things.
     list($commands_dir, $model_dir, $validators_dir, $library_dir, $view_dir, $helpers_dir, $helpers_app_dir, $drivers_dir, $app_dir, $view_layout_dir, $validator_error_messages, $lang) = Current::$config->gets('paths.commands', 'paths.model', 'paths.validators', 'paths.library', 'paths.view', 'paths.helpers', 'paths.helpers_app', 'paths.drivers', 'paths.app', 'paths.layouts', 'paths.validator_messages', 'lang');
     Controller::setDir($commands_dir);
     DataMapper::setMappersDir($model_dir);
     DataMapper::setObjectsDir($model_dir);
     Validator::setPath($validators_dir);
     Validator::loadStrings($validator_error_messages, $lang);
     Templater::setBaseDir($view_dir);
     Templater::setLayoutDir($view_layout_dir);
     Library::setPath($library_dir);
     Helpers::setPath($helpers_dir);
     Helpers::setAppPath($helpers_app_dir);
     Database::setPath($drivers_dir);
     StaticServer::setDir($app_dir);
     Cowl::timerEnd('cowl set defaults');
     Cowl::timer('cowl plugins load');
     Current::$plugins = new Plugins();
     Cowl::timerEnd('cowl plugins load');
     // Load default helper
     Helpers::load('standard', 'form');
     Cowl::timerEnd('cowl init');
 }
Ejemplo n.º 8
0
 public function __get($name)
 {
     // // the conditions below should be replace by using the _get_relationship_type method
     // belongs to relationship
     if (in_array($name, $this->belongs_to)) {
         return $this->_belongs_to($name);
     } elseif (array_key_exists($name, $this->belongs_to) && is_array($this->belongs_to[$name])) {
         return $this->_belongs_to($name, $this->belongs_to[$name]);
     } elseif (in_array($name, $this->has_many)) {
         return $this->_has_many($name);
     } elseif (array_key_exists($name, $this->has_many) && is_array($this->has_many[$name])) {
         return $this->_has_many($name, $this->has_many[$name]);
         // for has_many :through
     } elseif (array_key_exists($name, $this->has_many_through)) {
         return $this->_has_many_through($name);
     } elseif (in_array($name, $this->has_one)) {
         return $this->_has_one($name);
     } elseif (array_key_exists($name, $this->has_one) && is_array($this->has_one[$name])) {
         return $this->_has_one($name, $this->has_one[$name]);
     } elseif (method_exists($this, $name)) {
         #echo $this;
         return $this->{$name}();
     } else {
         return parent::__get($name);
     }
 }
Ejemplo n.º 9
0
 public function __construct(Database $db, $user)
 {
     parent::__construct($db);
     $this->table('logins');
     $this->columns(array('id', 'users_id', 'unixtime'));
     $this->has_one = array($user);
 }
Ejemplo n.º 10
0
 public function __construct()
 {
     foreach ($this->objects as $map) {
         $this->{strtolower($map . 'mapper')} = DataMapper::get($map);
     }
     $this->template = new Templater();
 }
Ejemplo n.º 11
0
 function delete_with_sub()
 {
     // getting the subsections
     $c = new Section();
     $c->where('parent_section', $this->id);
     $c->get();
     // delete all subsections relations
     $c->delete_all();
     // delete all children
     $cont = new Content();
     $cont->get_where_parent_section($this->id);
     $cont->delete_all();
     // update all the sections sort after that section
     // that in the same parent section
     $s = new Section();
     $s->where('sort >', $this->sort);
     $s->where('parent_section', $this->parent_section);
     $s->get();
     foreach ($s->all as $item) {
         $item->sort--;
         $item->save();
     }
     //delete this section
     parent::delete($object);
 }
Ejemplo n.º 12
0
 function save($o = null, $log = true)
 {
     $action = $this->id ? 'updated' : 'inserted';
     parent::save($o);
     if ($log) {
         $this->logActivity($action);
     }
 }
Ejemplo n.º 13
0
 function Activity($target = null)
 {
     parent::__construct();
     if ($target) {
         $this->target_class = get_class($target);
         $this->target_id = $target->id;
     }
 }
Ejemplo n.º 14
0
 public function __construct($id = null)
 {
     if (!is_null($id)) {
         $this->setID($id);
     }
     $this->validator = new Validator();
     $this->validator->setStoreErrors(true);
     $this->mapper = DataMapper::get(get_class($this));
 }
Ejemplo n.º 15
0
 function getBannerPartners()
 {
     $result = $this->selectBannerStmt->execute();
     if (!$result) {
         throw new \Exception("Ошибка базы данных. Запрос на выборку партнеров не прошел");
     }
     $collection = parent::getCollection($this->selectBannerStmt);
     return $collection;
 }
Ejemplo n.º 16
0
 /**
  * Delete this student or related object.
  * If no parameters are set, this method deletes current student and all participant record related with this student.
  * @param DataMapper|string $object related object to delete from relation.
  * @param string $related_field relation internal name.
  */
 public function delete($object = '', $related_field = '')
 {
     if (empty($object) && !is_array($object) && !empty($this->id)) {
         $participant = new Participant();
         $participant->where_related($this);
         $participant->get();
         $participant->delete_all();
     }
     parent::delete($object, $related_field);
 }
Ejemplo n.º 17
0
 /**
  * Delete this test or related object.
  * If no parameters are set, this method deletes current test and all files associated with this test.
  * @param DataMapper|string $object related object to delete from relation.
  * @param string $related_field relation internal name.
  */
 public function delete($object = '', $related_field = '')
 {
     if (empty($object) && !is_array($object) && !empty($this->id)) {
         $path_to_test_files = 'private/uploads/unit_tests/test_' . $this->id;
         if (file_exists($path_to_test_files)) {
             unlink_recursive($path_to_test_files, TRUE);
         }
     }
     parent::delete($object, $related_field);
 }
Ejemplo n.º 18
0
 /**
  * Deletes relations (if parameters are set) or this object from database.
  * All comments which replies to this one will be deleted as well.
  * @param DataMapper|string $object related object to delete from relation.
  * @param string $related_field relation internal name.
  */
 public function delete($object = '', $related_field = '')
 {
     $this_id = $this->id;
     if (empty($object) && !is_array($object) && !empty($this_id)) {
         $comments = $this->comment->get_iterated();
         foreach ($comments as $comment) {
             $comment->delete();
         }
     }
     parent::delete($object, $related_field);
 }
Ejemplo n.º 19
0
 public function __construct(Database $db, $user = null)
 {
     parent::__construct($db);
     $this->table('blog');
     $this->columns(array('id', 'title', 'content', 'unixtime'));
     if (!empty($user) && $user instanceof User) {
         $this->has_one = array($user);
     } else {
         $this->has_one = array(new User($db));
     }
 }
Ejemplo n.º 20
0
 /**
  * {@inheritdoc}
  */
 public function __construct($id = null)
 {
     $trace = debug_backtrace();
     if ((empty($trace[2]['object']) || !$trace[2]['object'] instanceof DataMapper) && self::$isInstantiated) {
         throw new RuntimeException('System_setting can be instantiated only once!');
     }
     if ($this->hasTable($this->prefix . $this->table)) {
         parent::__construct($id);
     }
     self::$isInstantiated = true;
 }
Ejemplo n.º 21
0
 function deleteImg($id)
 {
     $item = parent::find($id);
     if ($item->getImg() == "") {
         return;
     }
     $query = $this->pdo->prepare("UPDATE news SET img = '' WHERE id = ?");
     $result = $query->execute(array($id));
     if (!$result) {
         throw new \Exception("Ошибка базы данных. Запрос на обновление поля изображения не прошел");
     }
     unlink("../content_imgs/news_logos/" . $item->getImg() . ".jpg");
 }
Ejemplo n.º 22
0
 /**
  * Overwrite of the get_iterated() function to add filters to the search.
  * Refer to DataMapper ORM for get_iterated() function details.
  *
  * @author	Woxxy
  * @param	integer|NULL $limit Limit the number of results.
  * @param	integer|NULL $offset Offset the results when limiting.
  * @return	DataMapper Returns self for method chaining.
  */
 public function get_iterated($limit = NULL, $offset = NULL)
 {
     // Get the CodeIgniter instance, since it isn't set in this file.
     $CI =& get_instance();
     // Check if the user is allowed to see protected chapters.
     if (!$CI->tank_auth->is_allowed()) {
         $this->where('hidden', 0);
     }
     /**
      * @todo figure out why those variables don't get unset... it would be
      * way better to use the iterated in almost all cases in FoOlSlide
      */
     return parent::get_iterated($limit, $offset);
 }
Ejemplo n.º 23
0
 function save($object = '', $related_field = '')
 {
     if (!$this->exists() || empty($this->code)) {
         $o = new CurriculumViate();
         $o->select_max('position');
         $o->get();
         if (count($o->all) != 0) {
             $max = $o->position + 1;
             $this->position = $max;
         } else {
             $this->postion = 1;
         }
     }
     return parent::save($object, $related_field);
 }
Ejemplo n.º 24
0
 function save($object = '', $related_field = '')
 {
     if (!$this->exists()) {
         $o = new Estatetype();
         $o->select_max('position');
         $o->get();
         if (count($o->all) != 0) {
             $max = $o->position + 1;
             $this->position = $max;
         } else {
             $this->postion = 1;
         }
     }
     return parent::save($object, $related_field);
 }
Ejemplo n.º 25
0
 function save($object = '', $related_field = '')
 {
     if (!$this->exists()) {
         $o = new productcatspec();
         $o->where("productcat_id", $this->productcat_id);
         $o->select_max('position');
         $o->get();
         if (count($o->all) != 0) {
             $max = $o->position + 1;
             $this->position = $max;
         } else {
             $this->postion = 1;
         }
     }
     return parent::save($object, $related_field);
 }
Ejemplo n.º 26
0
 /**
  * delete that section with all it's subsections
  * plus eliminate the gap between it's siblings sort
  **/
 public function delete($object = '', $related_field = '')
 {
     if (empty($object)) {
         // update all the sections sort after that section
         // that in the same parent section
         $s = new Section();
         $s->where('sort >', $this->sort);
         $s->where('parent_section', $this->parent_section);
         $s->get();
         foreach ($s as $item) {
             $item->sort--;
             $item->save();
         }
     }
     //delete this section
     parent::delete($object, $related_field);
 }
Ejemplo n.º 27
0
 /**
  * Delete this period or related object.
  * If no parameters are set, this method deletes current period and re-sort all other periods.
  * @param DataMapper|string $object related object to delete from relation.
  * @param string $related_field relation internal name.
  */
 public function delete($object = '', $related_field = '')
 {
     if (empty($object) && !is_array($object) && !empty($this->id)) {
         $lower_periods = new Period();
         $lower_periods->order_by('sorting', 'asc');
         $lower_periods->where('sorting > ', $this->sorting);
         $lower_periods->get_iterated();
         $ids = array();
         foreach ($lower_periods as $lower_period) {
             $ids[] = $lower_period->id;
         }
         if (count($ids) > 0) {
             $this->db->set('sorting', 'sorting-1', FALSE);
             $this->db->where_in('id', $ids);
             $this->db->update('periods');
         }
     }
     parent::delete($object, $related_field);
 }
Ejemplo n.º 28
0
 /**
  * Delete this object from database or specified relations.
  * If this object is deleted, all student files will be deleted as well.
  * @param DataMapper|string $object related object to delete from relation.
  * @param string $related_field relation internal name.
  */
 public function delete($object = '', $related_field = '')
 {
     $this_id = $this->id;
     $this_task_set_id = $this->task_set_id;
     $this_student_id = $this->student_id;
     parent::delete($object, $related_field);
     if (empty($object) && !is_array($object) && !empty($this_id)) {
         $task_set = new Task_set();
         $task_set->get_by_id($this_task_set_id);
         if ($task_set->exists()) {
             $student_files = $task_set->get_student_files($this_student_id);
             if (count($student_files) > 0) {
                 foreach ($student_files as $file) {
                     @unlink($file['filepath']);
                 }
             }
         }
     }
 }
Ejemplo n.º 29
0
 function save($object = '', $related_field = '')
 {
     if (!$this->exists() || empty($this->code)) {
         $o = new Cartitem();
         $o->select_max('position');
         $o->get();
         if (count($o->all) != 0) {
             $max = $o->position + 1;
             $this->position = $max;
         } else {
             $this->postion = 1;
         }
         $position = (string) $this->position;
         $l = 6 - strlen($position);
         $st = "";
         for ($i = 0; $i < $l; $i++) {
             $st .= "0";
         }
         $position = $st . $position;
         $this->code = $position;
     }
     return parent::save($object, $related_field);
 }
Ejemplo n.º 30
0
 function __construct($id = NULL)
 {
     parent::__construct($id);
 }