public static function validate($object, $fields, $message) { foreach ($fields as $fieldName) { if (isset($object->{$fieldName})) { $objClass = get_class($object); $objQuery = Make::a($objClass)->equal($fieldName, $object->{$fieldName}); $objIsNotUnique = isset($object->id) ? $objQuery->notEqual('id', $object->id)->exists() : $objQuery->exists(); if ($objIsNotUnique) { $object->errors[] = self::labelForObjectProperty($object, $fieldName) . ' ' . $message; } } } }
/** !Route GET */ function index() { $page = isset($this->request->get['page']) ? (int) $this->request->get['page'] : 1; $this->page = $page; $url = "http://macthemes2.net/forum/viewforum.php?id=24&p={$page}"; if (!is_cache_valid(url_cache_file($url))) { $html = download($url); $doc = phpQuery::newDocument($html); $rows = $doc['#punviewforum table tr > td.tcl']->parent(); $viewtopic_length = strlen('viewtopic.php?id='); foreach ($rows as $row) { $row = pq($row); $a = $row['a:first'][0]; $name = trim($a->text()); if (preg_match('/^\\[(theme|contest|contest theme)\\]/iu', $name)) { $id = substr($a->attr('href'), $viewtopic_length); if (!Make::a('Theme')->like('topic_id', $id)->exists()) { $artist = $row['td.tc4'][0]->text(); $byPos = strrpos($name, ' by '); if ($byPos !== false) { $name = substr($name, 0, $byPos); } $name = strip_tag_prefix($name); $theme = new Theme(); $theme->topic_id = $id; $theme->name = $name; $theme->artist = $artist; $theme->save(); } } } } $this->themeSet = $this->theme->all(); if (isset($this->request->get['flash'])) { $this->flash = $this->request->get['flash']; } }
function test() { $people = Make::a('Person')->in('id', array(1, 2, 3)); $this->assertEquals($people[0]->id, 1); $this->assertEquals($people[0]->phone, '321-456-7890'); }
function testTicket68FirstAfterEqual() { $person = Make::a('Person')->equal('phone', '321-456-7890')->first(); $this->assertEquals($person->id, 1); $this->assertEquals($person->phone, '321-456-7890'); }
/** !Route GET */ public function home() { $this->checkTables(); $this->classes = Make::a('RecessReflectorClass')->all()->orderBy('name'); $this->packages = Make::a('RecessReflectorPackage')->all()->orderBy('name'); }