コード例 #1
0
 public static function language_form($post, $args)
 {
     wp_nonce_field(plugin_basename(__FILE__), 'aceelpress_noncename');
     $language = Finder::factory('language')->find($args['args'][0]);
     echo "<textarea class='accelpress-mce' id='accel_" . rand(0, 10000) . "' name='" . $language->getFormName() . "[" . $language->id . "]' cols=100>" . htmlentities($language->translate($post->ID), ENT_QUOTES) . "</textarea>";
 }
コード例 #2
0
 public static function displayAll($className, $finderOpts = NULL)
 {
     $thisScript = admin_url() . '?' . $_ENV[QUERY_STRING];
     $objs = Finder::factory($className)->findAll($finderOpts);
     $table .= "<span class='wrap'><h2>" . trim(humanize($className)) . "s <a href='{$thisScript}&new=new' class='new add-new-h2'>New " . humanize($className) . "</a></h2></span>";
     if (!$objs) {
         return $table;
     }
     $fieldsToDisplay = $objs[0]->fieldsToDisplay();
     // $table .= self::commonJs();
     // displayOrder DnD stuff
     if ($displayOrderIndex = array_search('displayOrder', $fieldsToDisplay)) {
         $table .= "<div id='displayOrderResponse'></div>";
         $displayOrderClass = 'orderable';
         array_splice($fieldsToDisplay, $displayOrderIndex, 1);
         // remove it so it won't display
     }
     // parentID stuff
     if ($parentIDIndex = array_search('parentID', $fieldsToDisplay)) {
         // reorgranize $objs array
         foreach ($objs as $obj) {
             if ($obj->parentID) {
                 $children[$obj->parentID][] = $obj;
             } else {
                 $tmp[] = $obj;
             }
         }
         $objs = $tmp;
         array_splice($fieldsToDisplay, $parentIDIndex, 1);
         // remove it so it won't display
     }
     $table .= "<table class='wp-list-table widefat fixed {$displayOrderClass}' myClass='" . $className . "' id='obj' width='100%'><thead><tr>";
     // special columns
     if (is_int(array_search('active', $fieldsToDisplay))) {
         $table .= "<th class='categoryCell' style='width:55px'>Active</th>";
     }
     if ($objs[0]->hasExtra('featuredRecord')) {
         $table .= "<th class='categoryCell'  style='width:52px'>Featured</th>";
     }
     foreach ($fieldsToDisplay as $field) {
         if ($field == 'active') {
             continue;
         }
         $table .= "<th class='categoryCell'>" . humanize($field) . "</th>";
     }
     $table .= "<th class='categoryCell {sorter: false}'>Delete</th></tr></thead><tbody>\n";
     foreach ($objs as $obj) {
         $table .= self::rowForObject($obj, $fieldsToDisplay, $children);
     }
     $table .= "</tbody></table>";
     return $table;
 }
コード例 #3
0
 /**
  * Will get the desired objects as long as they're configured correctly
  *
  * i.e. var $hasMany = array('Class Name' => 'fieldName in that table');
  * e.g. var $hasMany = array('Expense' => 'categoryID'); // would go in the ExpenseCategory object
  *
  * Has And Belongs To Many - $habtm - objects we're joined to via record_record or a join table
  *
  *				Special option keys for $additionalFinderOpts:
  *					'associations' - 	BOOL default false - if you only want the association objects and not the actual objects themselves pass this in
  *										*NOTE* applies only to record_record
  */
 public function get($getKey, $additionalFinderOpts = NULL)
 {
     $className = ucfirst($getKey);
     $internalVarName = self::INTERNAL_VAR_PREFIX . $className;
     if (!$this->{$internalVarName} || !is_null($additionalFinderOpts)) {
         // has many
         if (array_key_exists($className, $this->hasMany)) {
             if (!$this->id) {
                 return array();
             }
             $classNameToFind = $this->hasMany[$className]['className'] ? $this->hasMany[$className]['className'] : $className;
             $opts = array('where' => $this->hasMany[$className]['field'] . " = '" . $this->id . "'");
             if ($this->hasMany[$className]['condition']) {
                 $opts['where'] .= ' AND ' . $this->hasMany[$className]['condition'];
             }
             if (is_null($additionalFinderOpts)) {
                 $opts['order'] = $this->hasMany[$className]['order'];
                 if ($this->hasMany[$className]['finderOpts']) {
                     $opts = Finder::optionMerge($opts, $this->hasMany[$className]['finderOpts']);
                 }
                 $this->{$internalVarName} = Finder::factory($classNameToFind)->findAll($opts);
                 // cache this object in the found object
                 foreach ($this->{$internalVarName} as $foundObj) {
                     if (array_key_exists($this->getClass(), $foundObj->belongsTo)) {
                         $foundObj->set($this->getClass(), $this);
                     }
                 }
             } else {
                 $opts = Finder::optionMerge($opts, $additionalFinderOpts);
                 return Finder::factory($classNameToFind)->findAll($opts);
             }
             // belongs to
         } elseif (array_key_exists($className, $this->belongsTo)) {
             // this is a special keyword for tables with: className and recordID
             if ($className == 'Object') {
                 $this->{$internalVarName} = Finder::factory($this->className)->find($this->recordID);
             } else {
                 $foreignKey = $this->belongsTo[$className]['field'];
                 $classNameToFind = $this->belongsTo[$className]['className'] ? $this->belongsTo[$className]['className'] : $className;
                 $this->{$internalVarName} = Finder::factory($classNameToFind)->find($this->{$foreignKey});
             }
             // has and belongs to many
         } elseif (array_key_exists($className, $this->habtm)) {
             if (!$this->id()) {
                 return array();
             }
             // via the Associator
             if ($this->habtm[$className]['table'] == 'record_record') {
                 $classNameToFind = $this->habtm[$className]['className'] ? $this->habtm[$className]['className'] : $className;
                 $associator = new Associator();
                 $objectFinderOpts = array();
                 if ($this->habtm[$className]['condition']) {
                     $opts['where'] = $this->habtm[$className]['condition'];
                 }
                 if ($this->habtm[$className]['objectFinderOpts']) {
                     $objectFinderOpts = Finder::optionMerge($opts, $this->habtm[$className]['objectFinderOpts']);
                 }
                 // return only the associations, not the objects themselves
                 if ($additionalFinderOpts['associations']) {
                     $refObj = new ReflectionClass(ucfirst($className));
                     return $associator->findAssociations($refObj->getStaticPropertyValue('tableName'), $this->getTableName(), $this->id());
                 }
                 if ($additionalFinderOpts) {
                     $objectFinderOpts = Finder::optionMerge($additionalFinderOpts, $objectFinderOpts);
                 }
                 $this->{$internalVarName} = $associator->findAllObjectsForClassWithTableAndRecord($classNameToFind, $this->getTableName(), $this->id(), $opts, $objectFinderOpts);
                 // TODO: any join table
             } else {
                 $joinTable = $this->habtm[$className]['table'];
                 $associationForeignKey = $this->habtm[$className]['associationForeignKey'];
                 $foreignKey = $this->habtm[$className]['foreignKey'];
                 $ro = new ReflectionClass($className);
                 $instance = $ro->newInstance();
                 $tableName = $instance->getTableName();
                 $finder = new Finder($instance);
                 // more generic join tables
                 if (isset($this->habtm[$className]['typeKey']) && isset($this->habtm[$className]['typeValue'])) {
                     $typeKey = $this->habtm[$className]['typeKey'];
                     $typeValue = $this->habtm[$className]['typeValue'];
                     $additionalAnd = " AND jt." . $typeKey . "='{$typeValue}' ";
                 }
                 $sql = "SELECT activeRecord.* FROM {$joinTable} AS jt, {$tableName} as activeRecord\n\t\t\t\t\t\t\t\tWHERE jt." . $associationForeignKey . "=activeRecord.id\n\t\t\t\t\t\t\t\tAND activeRecord.siteID='" . $this->siteID . "'\n\t\t\t\t\t\t\t\tAND jt." . $foreignKey . "='" . $this->id . "'\n\t\t\t\t\t\t\t\t{$additionalAnd}";
                 $this->{$internalVarName} = $finder->findAllWithSql($sql, $additionalFinderOpts);
             }
             // try extras for ease
         } elseif ($this->hasExtra($getKey)) {
             return $this->getExtras($getKey);
             // error
         } else {
             //dump( $this->habtm );
             throw new Exception("<br/><br/>-----oh crap you haven't configured your objects correctly for CLASSNAME: " . $className . "---------<br/><br/>");
         }
     }
     return $this->{$internalVarName};
 }
コード例 #4
0
 public function manager($ARclassName, $finderOpts = null, $displayOpts = null)
 {
     $ARclassName = ucfirst($ARclassName);
     $reflectionObj = new ReflectionClass($ARclassName);
     $obj = $reflectionObj->newInstance();
     $formName = $obj->getFormName();
     $thisScript = admin_url() . '?page=' . $_GET['page'] . '&as_action=' . $_GET['as_action'] . '&type=' . $_GET['type'];
     if (!$this->noBackToList) {
         $this->view .= "<a href='{$thisScript}'><< Back To List</a>";
     }
     // SAVE POSTED FORM
     if ($_POST[$formName]) {
         // $obj = Assembler::assemble($reflectionObj->newInstance($_POST[$formName]));
         $obj = $reflectionObj->newInstance($_POST[$formName]);
         if (array_key_exists('active', $obj->getColumns())) {
             $obj->active = $_POST[$formName]['active'] ? '1' : '0';
         }
         $saveResponse = $obj->save();
         // there was an error
         if ($saveResponse instanceof AccelErrorHandler) {
             $reload = "Not Saved";
             $reloadDescription = $saveResponse->errorHtml();
             $thisScript .= "&edit=" . $obj->id();
         } else {
             $reload = "Saved";
         }
         // EDIT
     } elseif ($id = $_GET['edit']) {
         $this->obj = Finder::factory($ARclassName)->find($id, 'id', $finderOpts);
         $this->view .= $this->obj->form();
         // DELETE
     } elseif ($id = $_GET['delete']) {
         $obj = Finder::factory($ARclassName)->find($id);
         if ($obj) {
             $obj->suicide();
             $reload = "Deleted";
         } else {
             $reload = "Already Deleted";
         }
         // NEW
     } elseif ($id = $_GET['new']) {
         // $obj = Assembler::assemble($reflectionObj->newInstance());
         $obj = $reflectionObj->newInstance();
         // look if specific values have been passed in through $_GET
         foreach ($obj->getColumns() as $fieldName => $type) {
             if (in_array($fieldName, array('id', 'adminAction', 'new'))) {
                 continue;
             }
             if (array_key_exists($fieldName, $_GET)) {
                 $info[$fieldName] = $_GET[$fieldName];
             }
         }
         // yes, something was passed, refresh the object
         // if($info) $obj = Assembler::assemble($reflectionObj->newInstance($info));
         if ($info) {
             $obj = $reflectionObj->newInstance($info);
         }
         $this->view .= $obj->form();
         // DISPLAY TABLE OF ALL
     } else {
         // $obj = Assembler::assemble($reflectionObj->newInstance());
         // $this->displayAll = true;
         // if ($displayOpts['paginate_override'] !== null) {
         // 	$obj->paginate = $displayOpts['paginate_override'];
         // }
         $this->view = FormBuilder::displayAll($ARclassName);
     }
     // display stuff
     if ($reload) {
         if (!$reloadDescription) {
             $reloadDescription = humanize($ARclassName) . " " . $obj->id();
         }
         // $this->statusMessage()->set($reload, $reloadDescription);
         $this->view = "<script type='text/javascript' charset='utf-8'>console.log('{$thisScript}');window.location.href='{$thisScript}';</script>";
         // hacky
         // header("Location: $thisScript");
     }
     $this->skipView();
 }
コード例 #5
0
ファイル: Finder.php プロジェクト: netacceleration/accelpress
 public function findAllWithSql($sql, $finderOpts = null)
 {
     $objects = array();
     global $printFinderSql;
     if ($printFinderSql) {
         print $sql . "---<br/>";
     }
     // debug
     $res = mysql_query($sql);
     if ($res) {
         while ($row = mysql_fetch_assoc($res)) {
             $object = $this->obj->newSelf($row);
             $objects[] = $this->thingsWeDoToEveryObject($object);
         }
     }
     if ($objects and $finderOpts) {
         $ids = mapIDs($objects);
         //$newClass = $object->getClass();
         $newOpts['where'] = "id IN(" . implode(",", $ids) . ")";
         $opts = $this->optionMerge($finderOpts, $newOpts);
         return Finder::factory($object->getClass())->findAll($opts);
     }
     return $objects;
 }